package com.google.code.mochaccino.framework.hibernate.provider.configuration.helper;
/*
 * Copyright 2012 Claude Houle claude.houle@gmail.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.util.Properties;
import org.hibernate.cfg.Environment;

/** Batch Operation Specific Configuration */
public final class ConfigurationHelperBatch implements ConfigurationHelper {

	/** Batch Versionned Data (Assume the jdbc driver returns proper count for executeBatchUpdate() */
	private boolean batchVersionedData = true;

	/** Order Inserts */
	private boolean orderInserts = true;

	/** Order Updates */
	private boolean orderUpdates = true;

	/** Statement Batch Size (Any non-zero will boost performance) */
	private int statementBatchSize = 1;

	@Override
	public void configure( Properties p ) {
		p.put( Environment.ORDER_UPDATES, Boolean.toString( orderUpdates ) );
		p.put( Environment.ORDER_INSERTS, Boolean.toString( orderInserts ) );
		p.put( Environment.STATEMENT_BATCH_SIZE, String.valueOf( statementBatchSize ) );
		p.put( Environment.BATCH_VERSIONED_DATA, String.valueOf( batchVersionedData ) );
	}

	public void setStatementBatchSize( int statementBatchSize ) {
		this.statementBatchSize = statementBatchSize;
	}

	public void setBatchVersionedData( boolean batchVersionedData ) {
		this.batchVersionedData = batchVersionedData;
	}

	public void setOrderInserts( boolean orderInserts ) {
		this.orderInserts = orderInserts;
	}

	public void setOrderUpdates( boolean orderUpdates ) {
		this.orderUpdates = orderUpdates;
	}
}
